
import java.io.IOException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException;
import org.jibble.pircbot.PircBot;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Aksel Kvitberg
 */
public class Main extends PircBot{
	Random r  = new Random();

	public Main(){
		this.setName("TestBot");
		try {
			this.connect("irc.lessthan3.net");
			this.joinChannel("#zubac2");
		} catch (IOException ex) {
			Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IrcException ex) {
			Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	public void onMessage(String channel, String sender, String login, String hostname, String message) {
         Pattern p = Pattern.compile("\\A!roll *(\\d+)?");
         Matcher m = p.matcher(message);
         int sides = 6;
         if (m.find()){
			 System.out.println("Found");
             if (m.group(1) != null){
				 System.out.println("Count: " + m.group(1));
                 sides = Integer.parseInt(m.group(1));
				 System.out.println("parse");
             }
             int result = r.nextInt(sides);
			 System.out.println(result);
             sendMessage(channel, sender + " rolled " + result);
         }
     }

	public static void main(String args[]){
		new Main();
	}
}
